String object2string(dynamic object, {String defaultValue = ''}) {
  if (object == null) {
    return defaultValue;
  }
  if (object is String) {
    return object;
  }
  return object.toString();
}

int object2int(dynamic object, {int defaultValue = 0}) {
  if (object == null) {
    return defaultValue;
  }
  if (object is int) {
    return object;
  }
  return int.tryParse(object.toString()) ?? defaultValue;
}

double object2double(dynamic object, {double defaultValue = 0.0}) {
  if (object == null) {
    return defaultValue;
  }
  if (object is double) {
    return object;
  }
  return double.tryParse(object.toString()) ?? defaultValue;
}

bool object2bool(dynamic object, {bool defaultValue = false}) {
  if (object == null || object! is bool) {
    return defaultValue;
  }
  return object;
}

List<T> object2list<T>(dynamic object, {List<T> defaultValue = const []}) {
  if (object == null) {
    return defaultValue;
  }

  if (object is List<T>) {
    return object;
  }

  try {
    return List<T>.from(object);
  } catch (e) {
    return defaultValue;
  }
}

Map<String, dynamic> object2map(dynamic object,
    {Map<String, dynamic> defaultValue = const {}}) {
  if (object == null) {
    return defaultValue;
  }

  if (object is Map<String, dynamic>) {
    return object;
  }

  try {
    return Map<String, dynamic>.from(object);
  } catch (e) {
    return defaultValue;
  }
}
